var url = "http://" + buildURL() + "/";

$(function() {
	
	if($(window).width()<1224){
		$('#rNav').hide();
		$('#droppable').css('width','950');
	}else{
		$('#rNav').show();
		$('#droppable').css('width',$(window).width()-300);
		$('#divOnline').css('height',$(window).height()-320);	
	}
	
	$(window).resize(function(){
		if($(window).width()<1224){
			$('#rNav').hide();
			$('#droppable').css('width','950');
		}else{
			$('#rNav').show();
			$('#droppable').css('width',$(window).width()-300);
			$('#divOnline').css('height',$(window).height()-320);	
		}
	});
	
	
	
	initTabs();
	getTables();
});


function getTables(){
	$.ajax({
	url: url + "tables/",
	cache: false
	}).done(function( html ) {
		$("#divTables").append(html);
		getReports();
	});
}

function getReports(){
	$.ajax({
	url: url + "reports/",
	cache: false
	}).done(function( html ) {
		$("#divReports").append(html);
		//getRequests("23","tbl_Purchase_Request","Purchase Request");
	});
}

function getRequests(id, tblname, formName){
	$.ajax({
	url: url + "recordview/" + id + "/" + tblname + "/" + formName,
	cache: false
	}).done(function( html ) {
		$("#divView").html("");
		$("#divView").append(html);
		initTabs();
		$('#tabs a').click();
		getQuickNav();
	});
}

function getQuickNav(){
	$.ajax({
	url: url + "quicknav/",
	cache: false
	}).done(function( html ) {
		$("#divQuickNav").append(html);
		$("#divQuickNav").jScrollPane({
			horizontalGutter:5,
			verticalGutter:5,
			'showArrows': false
		});
		$('.jspDrag').hide();
		$('.jspScrollable').mouseenter(function(){
			$(this).find('.jspDrag').stop(true, true).fadeIn('slow');
		});
		$('.jspScrollable').mouseleave(function(){
			$(this).find('.jspDrag').stop(true, true).fadeOut('slow');
		});
		getOnline();
	});
}
// For Online User
function getOnline(){
	$.ajax({
	url: url + "online/",
	cache: false
	}).done(function( html ) {
		$("#divOnline").append(html);
		$("#divOnline").jScrollPane({
			horizontalGutter:5,
			verticalGutter:5,
			'showArrows': false
		});
		$('.jspDrag').hide();
		$('.jspScrollable').mouseenter(function(){
			$(this).find('.jspDrag').stop(true, true).fadeIn('slow');
		});
		$('.jspScrollable').mouseleave(function(){
			$(this).find('.jspDrag').stop(true, true).fadeOut('slow');
		});
	});
}



// For Tabs
function initTabs(){
	$("#content .divTab").hide(); // Initially hide all content
	$("#tabs li:first").attr("id","current"); // Activate first tab
	$("#content div:first").fadeIn(); // Show first tab content
    
    $('#tabs a').click(function(e) {
        e.preventDefault();
        if ($(this).closest("li").attr("id") == "current"){ //detection for current tab
         return       
        }
        else{             
        $("#content .divTab").hide(); //Hide all content
        $("#tabs li").attr("id",""); //Reset id's
        $(this).parent().attr("id","current"); // Activate this
        $('#' + $(this).attr('name')).fadeIn(); // Show content for current tab
        }
    });
	
}